package com.beiing.tianshuai.tianshuai.home.model;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.HomeBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 *
 * @author LZQ
 * @date 2017/11/16
 */

public class HomeModelImpl implements IHomeModel {

    @Override
    public void getHomeContent(String uid, final CallBack<HomeBean> callBack) {
        DisposableObserver<HomeBean> observer = new DisposableObserver<HomeBean>() {
            @Override
            public void onNext(HomeBean homeBean) {
                callBack.result(homeBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getHomeContent(uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void getHomeList(int page, final CallBack<HomeBean> callBack) {
        DisposableObserver<HomeBean> observer = new DisposableObserver<HomeBean>() {
            @Override
            public void onNext(HomeBean homeBean) {
                callBack.result(homeBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getHomeList(page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
